#include <iostream>
using namespace std;
#include <cstring>
#include <cmath>

int getDis(char a,char b,int k) {
	if (a == ' ') {
		if (b == ' ')
			return 0;
		else
			return k;
	}
	else {
		if (b == ' ')
			return k;
		else
			return abs(a - b);
	}
}
int main() {
	string str1;
	string str2;
	cin >> str1;
	cin >> str2;
	str1.insert(str1.begin(), ' ');
	str2.insert(str2.begin(), ' ');
	int k;
	cin >> k;
	int N1 = str1.size();
	int N2 = str2.size();
	int* array1 = new int[N2];
	int* array2 = new int[N2];
	array1[0] = 0;
	int count = 0;
	for (int i = 1; i < N2; i++) {
		array1[i] = array1[i - 1] + k;
	}
	for (int i = 1; i < N1; i++) {
		if (count % 2 == 0)
			array2[0] = array1[0] + k;
		else
			array1[0] = array2[0] + k;
		for (int j = 1; j < N2; j++) {
			if(count%2==0)
				array2[j] = min(array1[j - 1] + getDis(str1[i], str2[j],k),min(array2[j - 1] +  k, array1[j] + k));
			else
				array1[j] = min(array2[j - 1] + getDis(str1[i], str2[j], k), min(array1[j - 1] + k, array2[j] + k));
		}
		count++;
	}
	if (count % 2 == 0)
		cout << array1[N2 - 1] << endl;
	else
		cout << array2[N2 - 1] << endl;
	return 0;
}